/**
 * 
 */
package travibot.ui.gui.forms.providers.content;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

import travibot.model.Field;
import travibot.model.Structure;
import travibot.model.Village;


/**
 * @author tajzivit
 *
 */
public class FieldsContentProvider implements ITreeContentProvider {

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
     */
    public Object[] getChildren(Object obj) {

        List<Structure> result = new ArrayList<Structure>();
        
        if(!(obj instanceof Village))
            return new Object[0];

        Village v = (Village)obj;
        if(v != null && v.isInitialized()){
            if(v.getStructures() != null){
                Iterator<Structure> fieldsIterator = v.getStructures().iterator();
                while(fieldsIterator.hasNext()){
                    
                    Structure s = fieldsIterator.next();
                    
                    if(s instanceof Field)
                        result.add(s);
                }
            }
        }
            
        return result.toArray();   
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
     */
    public Object getParent(Object arg0) {

        return null;
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
     */
    public boolean hasChildren(Object arg0) {

        return false;
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
     */
    public Object[] getElements(Object arg0) {

        return getChildren(arg0);
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.IContentProvider#dispose()
     */
    public void dispose() {

        // TODO Auto-generated method stub

    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
     */
    public void inputChanged(Viewer arg0, Object arg1, Object arg2) {

        // TODO Auto-generated method stub

    }

}
